package br.com.lh.urabuilder.util
{
	import br.com.lh.urabuilder.model.UraModelLocator;
	
	import flash.geom.Point;
	
	import mx.core.UIComponent;
	
	public class CoordinatesUtils
	{
		
		public static const SELF_ARROW_WIDTH:int = 30;
    	public static const SELF_ARROW_HEIGHT:int = 60;
		
		public function CoordinatesUtils()
		{
		}
		
		public static function getCanvasLocalToGlobalCoordinates():Point{
			var componentCanvas:UIComponent = UraModelLocator.getInstance().parent; 
			return componentCanvas.contentToGlobal(
					new Point(componentCanvas.x,componentCanvas.y));
			//contentYToGlobal = componentCanvas.contentToGlobal(new Point(componentCanvas.x,componentCanvas.y)).y;
		}
		
		public static function getLineLength(startPoint:Point,endPoint:Point):Number{
			var deltaX:Number = endPoint.x - startPoint.x;
			var deltaY:Number = endPoint.y - startPoint.y;
			return Math.sqrt(Math.pow(deltaX,2) + Math.pow(deltaY,2));
		}
		
		public static function getAngleInRad(startPoint:Point,endPoint:Point):Number{
			var deltaX:Number = endPoint.x - startPoint.x;
			var deltaY:Number = endPoint.y - startPoint.y;
			return Math.atan(deltaY/deltaX);
		}
		
		public static function getAngleInDegrees(startPoint:Point,endPoint:Point):Number{
			var deltaX:Number = endPoint.x - startPoint.x;
			var deltaY:Number = endPoint.y - startPoint.y;
			var baseValue:Number =Math.atan(deltaY/deltaX) *180/Math.PI
			if (deltaY >0 && deltaX >0){
				return baseValue;
			}else if (deltaY >0 && deltaX <0){
				return 180 + baseValue;
			}else if (deltaY < 0 && deltaX >0){
				return 360 + baseValue;
			}else{
				return 180 + baseValue;
			}
		}
		
		public static function getRotatedStartPoint(startPoint:Point,height:Number,angle:Number):Point{
			return new Point(startPoint.x + (height/2 * Math.cos(angle)),startPoint.y - (height/2 * Math.sin(angle)));
		}
		
		
	}
}